package mi.payment.utils.transaction;

import android.content.Context;

import java.util.Map;

import mi.payment.bean.db.TradeData;
import mi.payment.utils.iso8583.EncodePackage;
import mi.payment.utils.iso8583.FieldUtils;
import mi.payment.utils.iso8583.MsgField;
import mi.payment.utils.secure.TerminalSecure;

/**
 * @author tomcat on 2017/2/17.
 */
public class PayResultQueryTask extends TransactionTask<TradeData, Void, TradeData> {

    protected PayResultQueryTask(Context context) {
        super(context, true);
    }

    @Override
    protected void onBegin(TradeData[] params) {
        tradeData = params[0];
        dbBean = tradeData.getPayDetail();
    }

    @Override
    protected TradeData appointResult() {
        return tradeData;
    }

    @Override
    protected Map<String, MsgField> preAssembly() {
        return EncodePackage.preAssemblyBase("2020008000C40011");
    }

    @Override
    protected byte[] changeAndAssembly(Map<String, MsgField> fieldMap) {
        dbBean.setProcessCode("500200");
        dbBean.setTransType("01");
        dbBean.setNetManageCode("000");
        dbBean.setTerminalDate(System.currentTimeMillis() / 1000);
        Map<String, MsgField> map = FieldUtils.fillEachFieldValue(fieldMap, tradeData);
        return EncodePackage.assembly(map, "0200", TerminalSecure.PROCESSREQUEST_NONE);
    }


}